package spring.security.core.validatecode;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import spring.security.core.validatecode.service.SmsCodeSender;
import spring.security.core.validatecode.service.ValidateCodeGenerator;
import spring.security.core.validatecode.service.impl.DefaultSmsCodeSender;
import spring.security.core.validatecode.service.impl.ImageCodeGenerator;
import spring.security.core.validatecode.service.impl.SmsCodeGenerator;

@Configuration
public class ValidateCodeBeanConfig {
	
	@Bean
	//如果容器中存在一个name=imageCodeGenerator的Bean,那么就不走下面的方法创建Bean
	@ConditionalOnMissingBean(name = "imageCodeGenerator")
	public ValidateCodeGenerator imageCodeGenerator() {
		ImageCodeGenerator codegenerator = new ImageCodeGenerator();
		return codegenerator;
	}
	
	@Bean
	@ConditionalOnMissingBean(SmsCodeSender.class)
	public SmsCodeSender smsCodeSender() {
		return new DefaultSmsCodeSender();
	}
}
